#include "FollowerGangster.h"
#include "Controller.h"
#include "Mob.h"
#include "Field.h"

bool FollowerGangster::action( QKeyEvent* ) {
    bool returnValue = false;
    #ifdef AIENABLED
    Mob* m = getMob();
    Mob* player = m->getField()->getPlayer();
    int speed = m->getMoveSpeed();
    for( int i = 0; i < speed; i++ ) {
        /*evade();
        Direction d = m->getField()->enemyInSight( m );
        if( d != NONE ) m->attack( d ); */
        if( evade() ) {
            returnValue = true;
            continue;
        }
        if( hasPath() ) {
            Direction c = cellToDirection( getPath(), m );
            if( !(m->getField()->move( c, 1, m )) ) {
                clearPath();
            } else {
                returnValue = true;
            }
        } else {
            if( player != 0 ) {
                findPath( m->getX(), m->getY(),
                          player->getX(), player->getY() );
            } else {
                findPath( m->getX(), m->getY(),
                          60, 60 );
            }
        }
        Direction d = m->getField()->enemyInSight( m );
        if( d != NONE ) m->attack( d );
    }
    #endif
    return returnValue;
}
